﻿
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Data;
using System.Data.OracleClient;
using Osiptel.CCPP.BE;

namespace Osiptel.CCPP.DL
{
    public class IndicadorDL
    {

        #region "No Transaccionales"

        public Int32 ObtenerVisita(IndicadorBE oInd)
        {
            try
            {

                Int32 sValor = 0;
                using (OracleCommand cmd = new OracleCommand())
                {
                    cmd.CommandText = "COMUN.PKG_INDICADOR.SP_MOSTRAR_CAB_INDICADOR";
                    cmd.CommandType = CommandType.StoredProcedure;

                    OracleParameter prm1 = new OracleParameter("SAPLICACION", OracleType.VarChar);
                    OracleParameter prm2 = new OracleParameter("STIPO", OracleType.VarChar);
                    OracleParameter prm3 = new OracleParameter("NCANTIDAD", OracleType.Number);

                    prm1.Direction = ParameterDirection.Input;
                    prm2.Direction = ParameterDirection.Input;
                    prm3.Direction = ParameterDirection.Output;

                    prm1.Value = oInd.aplicacion;
                    prm2.Value = oInd.tipo;

                    cmd.Parameters.Add(prm1);
                    cmd.Parameters.Add(prm2);
                    cmd.Parameters.Add(prm3);

                    using (DL_CONEXION NewConexion = new DL_CONEXION())
                    {
                        int ret = NewConexion.ejecutaSQL(cmd);
                        sValor = Convert.ToInt32(Convert.ToString(cmd.Parameters["NCANTIDAD"].Value));
                        return sValor;
                    }
                }
            }
            catch (Exception ex)
            {
                throw ex;
            }

        }

        public DataTable ObtenerFecha(IndicadorBE oInd)
        {
            try
            {
                DataTable dtFecha = new DataTable();
                using (OracleCommand cmd = new OracleCommand())
                {
                    cmd.CommandText = "COMUN.PKG_INDICADOR.SP_OBTENER_FECHA_INDICADOR";
                    cmd.CommandType = CommandType.StoredProcedure;

                    OracleParameter prm1 = new OracleParameter("SAPLICACION", OracleType.VarChar);
                    OracleParameter prm2 = new OracleParameter("STIPO", OracleType.VarChar);
                    OracleParameter prm3 = new OracleParameter("SUSUARIO", OracleType.VarChar);
                    OracleParameter prm4 = new OracleParameter("OLISTADO", OracleType.Cursor);

                    prm1.Direction = ParameterDirection.Input;
                    prm2.Direction = ParameterDirection.Input;
                    prm3.Direction = ParameterDirection.Input;
                    prm4.Direction = ParameterDirection.Output;

                    prm1.Value = oInd.aplicacion.Trim();
                    prm2.Value = oInd.tipo.Trim();
                    prm3.Value = oInd.usuario.Trim();

                    cmd.Parameters.Add(prm1);
                    cmd.Parameters.Add(prm2);
                    cmd.Parameters.Add(prm3);
                    cmd.Parameters.Add(prm4);

                    using (DL_CONEXION NewConexion = new DL_CONEXION())
                    {
                        dtFecha = NewConexion.getTable(cmd);
                        return dtFecha;
                    }
                }
            }
            catch (Exception ex)
            {
                throw ex;
            }

        }

        #endregion

        #region "Transaccionales"

        public void mInsertarIndicador(IndicadorBE oInd)
        {
            try
            {
                string sIdCharla = string.Empty;
                string sNroCharla = string.Empty;
                using (OracleCommand cmd = new OracleCommand())
                {
                    cmd.CommandText = "COMUN.PKG_INDICADOR.SP_INSERTAR_CAB_INDICADOR";
                    cmd.CommandType = CommandType.StoredProcedure;

                    OracleParameter prm1 = new OracleParameter("SAPLICACION", OracleType.VarChar);
                    OracleParameter prm2 = new OracleParameter("STIPO", OracleType.VarChar);
                    OracleParameter prm3 = new OracleParameter("SUSUARIO", OracleType.VarChar);
                    OracleParameter prm4 = new OracleParameter("SIP", OracleType.VarChar);

                    prm1.Direction = ParameterDirection.Input;
                    prm2.Direction = ParameterDirection.Input;
                    prm3.Direction = ParameterDirection.Input;
                    prm4.Direction = ParameterDirection.Input;

                    prm1.Value = oInd.aplicacion;
                    prm2.Value = oInd.tipo;
                    prm3.Value = oInd.usuario;
                    prm4.Value = oInd.ip;

                    cmd.Parameters.Add(prm1);
                    cmd.Parameters.Add(prm2);
                    cmd.Parameters.Add(prm3);
                    cmd.Parameters.Add(prm4);

                    using (DL_CONEXION NewConexion = new DL_CONEXION())
                    {
                        int ret = NewConexion.ejecutaSQL(cmd);
                    }
                }
            }
            catch (Exception ex)
            {
                throw ex;
            }
        }

        #endregion

    }
}
